package com.niuwa.p2p.listener;


import java.util.List;

import javax.servlet.ServletContextEvent;

import org.apache.log4j.Logger;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

import com.niuwa.p2p.core.manager.DictManager;
import com.niuwa.p2p.entity.Dictionary;
import com.niuwa.p2p.service.dictionary.DictionaryService;




public class OprContextLoaderListener extends ContextLoaderListener {
	
	private static Logger log = Logger.getLogger(OprContextLoaderListener.class);
	@Override
	public void contextInitialized(ServletContextEvent event) {
		super.contextInitialized(event);
		WebApplicationContext context =  getCurrentWebApplicationContext();
		DictionaryService dictService = context.getBean(DictionaryService.class);
		List<Dictionary> list = null;
		try {
			long startTime = System.currentTimeMillis();
			log.info("=============》加载数据字典开始！");
			list = dictService.getAllDictionary();
			DictManager.getInstance().init(list);
			long endTime = System.currentTimeMillis();
			log.info("=============》加载数据字典结束！一共花费"+(endTime-startTime)+"毫秒");
		} catch (Exception e) {
			log.error("加载数据字典出错");
			e.printStackTrace();
			
		}
	}

}
